package org.apache.guacamole.net.example;

import javax.servlet.http.HttpServletRequest;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.net.GuacamoleSocket;
import org.apache.guacamole.net.GuacamoleTunnel;
import org.apache.guacamole.net.InetGuacamoleSocket;
import org.apache.guacamole.net.SimpleGuacamoleTunnel;
import org.apache.guacamole.protocol.ConfiguredGuacamoleSocket;
import org.apache.guacamole.protocol.GuacamoleConfiguration;
import org.apache.guacamole.servlet.GuacamoleHTTPTunnelServlet;

/**
 * @author yfdai
 */
public class TutorialGuacamoleTunnelServlet
        extends GuacamoleHTTPTunnelServlet {

  @Override
  protected GuacamoleTunnel doConnect(HttpServletRequest request)
          throws GuacamoleException {

    // Create our configuration
    GuacamoleConfiguration config = new GuacamoleConfiguration();
    config.setProtocol("vnc");
    config.setParameter("hostname", "localhost");
    config.setParameter("port", "5900");
    config.setParameter("password", "123456");

    // Connect to guacd - everything is hard-coded here.
    GuacamoleSocket socket = new ConfiguredGuacamoleSocket(
            new InetGuacamoleSocket("172.168.1.35", 4822),
            config
    );

    // Return a new tunnel which uses the connected socket
    return new SimpleGuacamoleTunnel(socket);

  }

}